package br.com.massai.model.entity;

import java.math.BigDecimal;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

import org.hibernate.envers.Audited;

@Entity
@Audited
@Table(name = "ENTRY_ITEM")
@NamedQueries({
	@NamedQuery(name = "EntryItem.find", query = "SELECT e FROM EntryItem e"),
	@NamedQuery(name = "EntryItem.duplicate", query = "SELECT COUNT(e) FROM EntryItem e WHERE e.id =:id") //TODO check condition of duplicate
})
public class EntryItem extends GenericEntity {

	private static final long serialVersionUID = -6204382284720506802L;

	@Id
	@SequenceGenerator(name = "seqEntryItem", sequenceName = "seq_entry_item", allocationSize = 1)
	@GeneratedValue(generator = "seqEntryItem", strategy = GenerationType.SEQUENCE)
	private Long id;
	
	@Column(name = "QUANTITY", precision = 10, scale = 2, columnDefinition = "NUMERIC(10,2)")
	private BigDecimal quantity;
	
	@Column(name = "VALUE_PERCENTAGE", precision = 10, scale = 4, columnDefinition = "NUMERIC(10,4)")
	private BigDecimal valuePercentage;
	
	@Column(name = "UNIT_PRICE", precision = 10, scale = 2, columnDefinition = "NUMERIC(10,2)")
	private BigDecimal unitPrice;
	
	@Column(name = "OBSERVATION", nullable = true, columnDefinition = "TEXT")
	private String observation;
	
	@Embedded
	private BudgetItem budgetItem;
	
	@ManyToOne(optional = false, fetch = FetchType.LAZY, cascade = CascadeType.REFRESH)
	@JoinColumn(name = "ENTRY_ID", referencedColumnName = "ID")
	private Entry entry;
	
	@ManyToOne(optional = false, fetch = FetchType.LAZY, cascade = CascadeType.REFRESH)
	@JoinColumn(name = "GROUP_ITEM_ID", referencedColumnName = "ID")
	private GroupItem groupItem;

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public BigDecimal getQuantity() {
		return quantity;
	}

	public void setQuantity(BigDecimal quantity) {
		this.quantity = quantity;
	}

	public BigDecimal getValuePercentage() {
		return valuePercentage;
	}

	public void setValuePercentage(BigDecimal valuePercentage) {
		this.valuePercentage = valuePercentage;
	}

	public BigDecimal getUnitPrice() {
		return unitPrice;
	}

	public void setUnitPrice(BigDecimal unitPrice) {
		this.unitPrice = unitPrice;
	}

	public String getObservation() {
		return observation;
	}

	public void setObservation(String observation) {
		this.observation = observation;
	}

	public BudgetItem getBudgetItem() {
		return budgetItem;
	}

	public void setBudgetItem(BudgetItem budgetItem) {
		this.budgetItem = budgetItem;
	}

	public Entry getEntry() {
		return entry;
	}

	public void setEntry(Entry entry) {
		this.entry = entry;
	}

	public GroupItem getGroupItem() {
		return groupItem;
	}

	public void setGroupItem(GroupItem groupItem) {
		this.groupItem = groupItem;
	}
	
}